package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.demo.dao.Mapper.UserMapper;
import com.example.demo.entity.User;

/**
 * @author BuerYouth
 */
@RestController
public class TestController {

    @Autowired
    UserMapper userMapper;

    /** 增添数据 */
    @PostMapping("/insert")
    public Object insert(String name) {
        User user = new User();
        user.setName(name);
        return userMapper.insert(user);
    }

    /** 查询数据 */
    @GetMapping("/show")
    public Object show() {
        return userMapper.selectList(null);
    }

    /** 删除数据 */
    @DeleteMapping("/delete")
    public Object delete(Integer id) {
        return userMapper.deleteById(id);
    }

    /** 修改数据 */
    @PutMapping("update")
    public Object update(Integer id, String name) {
        User user = new User();
        user.setId(id);
        user.setName(name);
        return userMapper.updateById(user);
    }
}